package cn.kgc.javaweb.utils;

import cn.hutool.json.JSONUtil;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: mosin
 * @version: v1.0  2022/6/27
 */
public final class ResponseUtil {

  private   ResponseUtil(){};

  public static  void  write(HttpServletResponse response,Object object) throws IOException {
      response.setContentType("application/json;charset=utf-8");
      PrintWriter writer = response.getWriter();
      // 将响应数据转换为json字符串
      String s = JSONUtil.toJsonStr(object);
      writer.write(s);
      writer.close();
  }


}
